<?php

class UserSortAction extends BaseAction {
	
	public function index() {
		$uid = (int)$_REQUEST['uid'];
		
		$m_sort = D('Sort');
		$list = $m_sort->findAll();
		
		$this->assign('uid',$uid);
		$this->assign('total',count($list));
		$this->assign('list',$list);
		
		$this->display();
	}
	
	public function save() {
		$str_userSorts = $_REQUEST['sorts'];
		$uid = (int)$_REQUEST['uid'];
		
		$m_userSort = D("UserSort");
		
		$m_userSort->where('uid='.$uid)->delete();
		
		$arr_userSorts = explode(',', $str_userSorts);
		for($i=0;$i<count($arr_userSorts);$i++) {
			$data['uid'] = $uid;
			$data['sid'] = $arr_userSorts[$i];
			if( false === $m_userSort->add($data))
			{
				//失败
				echo 0;
				return ;
			}
		}
		//成功
		echo 1;		
	}
	
}

?>